package com.risenb.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.risenb.bean.Permission;
import com.risenb.dao.PermissionMapper;
import com.risenb.service.PermissionService;

@Service
public class PermissionServiceImpl implements PermissionService {
	
	@Autowired
	PermissionMapper permissionMapper;
	
	@Override
	public List<Permission> queryAll() {
		return permissionMapper.queryAll();
	}
	@Override
	public int removePermissionById(Integer id) {
		return permissionMapper.removePermissionById(id);
	}
	@Override
	public int createPermission(Permission record) {
		return permissionMapper.createPermission(record);
	}
	
	@Override
	public Permission queryPermissionById(Integer id) {
		return permissionMapper.queryPermissionById(id);
	}
	@Override
	public int modifyPermissionById(Permission record) {
		return permissionMapper.modifyPermissionById(record);
	}
	
	@Override
	public List<Permission> queryMenus() {
		List<Permission> ps = permissionMapper.queryMenus();
		for (int i = 0; i < ps.size(); i++) {
			ps.get(i).setChirlds(permissionMapper.queryPermissionByParentId(ps.get(i).getId()));
		}
		return ps;
	}
	@Override
	public List<Permission> queryPermissionByParentId(Integer parentid) {
		return permissionMapper.queryPermissionByParentId(parentid);
	} 

}
